(function(){
    return {
        import:[
            {
                url:"js/readTable.js"
            },
            {
                url:"css/code.auto.css"
            }
        ],
        init:function(){
        },
        data:{
            packageName:"",
            projectName:"",
            sql:"",
            hideBtn:false,
        },
        before:function(data){
            var _this=this;
            if(_this.params.packageName!=null){
                data.packageName=_this.params.packageName;
            }
            if(_this.params.projectName!=null){
                data.projectName=_this.params.projectName;
            }
            var packageName=$.cookie(_this.modulePath+"packageName");
            var projectName=$.cookie(_this.modulePath+"projectName");
            data.packageName=packageName?packageName:"";
            data.projectName=projectName?projectName:"";
            if(_this.params.sql!=null){
                data.sql=_this.params.sql;
            }
            if(this.params.hideBtn!=null){
                data.hideBtn=this.params.hideBtn;
            }
            if(data.hideBtn==null){
                data.hideBtn=false;
            }
            return data;
        },
        after:function(){
            var _this=this;
            _this.$(".e-go-mysql").click(function(){
                var data=_this.toMap(".data-param");
                if(data.projectName){
                    $.cookie(_this.modulePath+"projectName",data.projectName,{path:"/",expires:365});
                }
                if(data.packageName) {
                    $.cookie(_this.modulePath + "packageName", data.packageName, {path: "/", expires: 365});
                }
               DsModule.to("module/tableCreateCode/mysqlTable");
            });
            _this.$(".e-downloadBase").click(function(){
                if(!_this.$(".data-form").validate().form()){
                    return;
                }
                var data=_this.toMap(".data-param");
                $.cookie(_this.modulePath+"projectName",data.projectName,{path:"/",expires:365});
                $.cookie(_this.modulePath+"packageName",data.packageName,{path:"/",expires:365});
                var exportForm = $("<form target='_blank' action='"+window.api+"codeDownload/baseProject' method='post' style='display: none'></form>")
                exportForm.append("<input type='hidden' name='token' value='"+window.sysUser.token+"'/>")
                exportForm.append("<input type='hidden' name='projectName' value='"+data.projectName+"'/>")
                exportForm.append("<input type='hidden' name='packageName' value='"+data.packageName+"'/>")
                $(document.body).append(exportForm);
                exportForm.submit();
                exportForm.remove();

            });
            _this.$(".e-downloadBaseKey").click(function() {
                if(!_this.$(".data-form").validate().form()){
                    return;
                }
                var data=_this.toMap(".data-param");
                $.cookie(_this.modulePath+"projectName",data.projectName,{path:"/",expires:365});
                $.cookie(_this.modulePath+"packageName",data.packageName,{path:"/",expires:365});
                ajaxPost({
                    url: "codeDownload/baseProjectKey",
                    data: data,
                    success: function (data) {
                        swal({
                            title: "下载key",
                            text: data.data,
                            confirmButtonText:"确定"
                        });
                    }
                });
            });
            _this.$(".e-resolving").click(function(){
                if(!_this.$(".data-form").validate().form()){
                    return;
                }
                var data=_this.toMap(".data-param");
                var sql=_this.$(".sqlText").val();
                if(sql==""){
                    toastr.error("sql不能为空");
                    return;
                }
                var json=readTable.read(sql);
                json.projectName=data.projectName;
                json.packageName=data.packageName;
                $.cookie(_this.modulePath+"projectName",data.projectName,{path:"/",expires:365});
                $.cookie(_this.modulePath+"packageName",data.packageName,{path:"/",expires:365});
                var m= DsModule.getModule("table-data");
                if(m!=null){
                    m.remove();
                }
                m=new Module("module/tableCreateCode/tableData");
                m.params=json;
                m.load("table-data");

            });
        }
    }
});